home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / ShellPanel / Save.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  55 lines

  1. /* File: Save.m - (Interactive) Unix shell version of SavePanel
  2.  *
  3.  * By: Christopher Lane (lane@sumex-aim.stanford.edu)
  4.  *
  5.  * Date: 10 November 1992
  6.  *
  7.  * Copyright: 1990, 1991 & 1992 by The Leland Stanford Junior University.
  8.  */
  9.  
  10. #import <stdlib.h>
  11. #import <getopt.h>
  12. #import <appkit/SavePanel.h>
  13. #import <appkit/Application.h>
  14.  
  15. #define USAGE "usage: %s [-f file] [-d directory] [-t type] [-p prompt] [-T title] [-u]\n"
  16. #define EXIT_USAGE (2)
  17.  
  18. void main(int argc, char *argv[])
  19. {
  20.     SavePanel *panel;
  21.     const char *name = NULL, *path = NULL;
  22.     int option, status = EXIT_SUCCESS;
  23.     
  24.     NXApp = [Application new];
  25.     panel = [SavePanel new];
  26.     
  27.     while ((option = getopt(argc, argv, "f:d:t:p:T:u")) != EOF)
  28.         switch (option) {
  29.         case 'f': name = optarg; break;
  30.         case 'd': path = optarg; break;
  31.         case 't': [panel setRequiredFileType:optarg]; break;
  32.         case 'p': [panel setPrompt:optarg]; break;
  33.         case 'T': [panel setTitle:optarg]; break;
  34.         case 'u': [panel setTreatsFilePackagesAsDirectories:YES]; break;
  35.         default : status = EXIT_USAGE;
  36.         }
  37.     if (optind < argc) status = EXIT_USAGE;
  38.  
  39.     if (status == EXIT_USAGE) (void) fprintf(stderr, USAGE, [NXApp appName]);
  40.     else {
  41.         int context = [NXApp activateSelf:YES];
  42.         
  43.         if ([panel runModalForDirectory:path file:name]) (void) puts([panel filename]);
  44.         else status = EXIT_FAILURE;
  45.         
  46.         if (context) (void) [NXApp activate:context];
  47.         }
  48.     
  49.     [panel free];
  50.  
  51.     [NXApp free];
  52.     
  53.     exit(status);
  54. }
  55.